package com.example.dagger2one.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.dagger2one.R;
import com.example.dagger2one.model.Data;
import com.example.dagger2one.model.ImageUrls;
import com.example.dagger2one.view.MultiImageView;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @作者: njb
 * @时间: 2019/7/23 11:49
 * @描述:
 */
public class DynamicActivity extends AppCompatActivity {
    CommonAdapter<String> mAdapter;
    List<String> mList = new ArrayList<>();

    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private List<ImageUrls> manyGrils = new ArrayList<>();
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dynamic);
        ButterKnife.bind(this);
        initData();

        initAdapter();

        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(mAdapter);

    }

    private void initData() {
        for(int i=0;i<9;i++){
            ImageUrls imageUrls = new ImageUrls();
            mList.add("http://opgirl-tmp.adbxb.cn/images2/mi/2202/148_ce2b24f5ea4fadaf6c5591416e7990dc_75.jpg");
            mList.add("http://opgirl-tmp.adbxb.cn/images3/mi/20/144_dc7b83c64f60363a8212f01eef43f513_75.jpg");
            mList.add("http://i1.go2yd.com/corpimage.php?url=http://si1.go2yd.com/get-image/0CZZQOCHE3M&source=mb&type=_896x504");
            mList.add("http://opgirl-tmp.adbxb.cn/images2/mi/1447/148_62de05945c28dbccaeb92f131f26f972_75.jpg");
            mList.add("http://opgirl-tmp.adbxb.cn/images2/mi/1240/142_b2f099d4f8576543cb0b0c3878cae26e_75.jpg");
            mList.add("http://i1.go2yd.com/corpimage.php?url=http://si1.go2yd.com/get-image/09yg7aATwp6&source=mb&type=_896x504");
            mList.add("http://opgirl-tmp.adbxb.cn/images2/mi/1307/206_773d003844d1966a7ce0cee1d245155a_75.jpg");
            mList.add("http://opgirl-tmp.adbxb.cn/images2/mi/2847/206_da5207eb0798f155572dca227ddf0411_75.jpg");
            mList.add("http://opgirl-tmp.adbxb.cn/images2/mi/1392/206_7c9ab9991319e284c8ce781481a866a4_75.jpeg");
            mList.add("http://opgirl-tmp.adbxb.cn/images1/mi/2566/208_cfcb6e2cd501aadf61fc572119ad8a29_75.jpg");
            imageUrls.setImageUrls(mList);
            manyGrils.add(imageUrls);
        }

    }

    private void initAdapter() {

        mAdapter = new CommonAdapter<String>(this, R.layout.item_dynamic_image, mList) {
            @Override
            protected void convert(ViewHolder holder, String s, int position) {
                MultiImageView multiImage = holder.getView(R.id.multi_image);
                holder.setText(R.id.tv_title, (position + 1) + "张图");
                multiImage.setList(mList);
                final int pos = position;
                multiImage.setOnItemClickListener(new MultiImageView.OnItemClickListener() {
                    @Override
                    public void onItemClick(View view, int position) {
                        Toast.makeText(DynamicActivity.this, position+"", Toast.LENGTH_SHORT).show();
                    }
                });
            }
        };

    }
}
